﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text;
using BLL;

public partial class wechat_locate : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        AddWechatJSConfig("getLocation");
    }

    /// <summary>
    /// 调用微信接口（只能在Page_Load事件中调用）
    /// </summary>
    /// <param name="apis"></param>
    protected void AddWechatJSConfig(params string[] apis)
    {
        string JSAppID = "";
        string JSTimeStamp = "";
        string JSNonceStr = "";
        Wechat wcin = new Wechat();
        string sign = wcin.GetJSSignPublic(this.Request.Url.ToString(), out JSAppID, out JSTimeStamp, out JSNonceStr);
        if (!string.IsNullOrEmpty(sign))
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("<script src='http://res.wx.qq.com/open/js/jweixin-1.0.0.js'></script>\n");
            sb.Append("<script language='javascript'>\n");
            sb.Append("wx.config({\n");
            sb.Append("debug: false,\n");
            sb.Append("appId: '");
            sb.Append(JSAppID);
            sb.Append("',\n");
            sb.Append("timestamp: ");
            sb.Append(JSTimeStamp);
            sb.Append(",\n");
            sb.Append("nonceStr:'");
            sb.Append(JSNonceStr);
            sb.Append("',\n");
            sb.Append("signature:'");
            sb.Append(sign);
            sb.Append("',\n");
            sb.Append("jsApiList:[");
            if (apis != null && apis.Length > 0)
            {
                sb.Append("'");
                sb.Append(string.Join("','", apis));
                sb.Append("'");
            }
            sb.Append("]\n");
            sb.Append("});\n");
            sb.Append("</script>\n");
            this.ClientScript.RegisterClientScriptBlock(this.GetType(), "",
                sb.ToString());
        }
    }
}